#!/bin/bash

ip=$1

hostname=$2

passwd=$3

# if hosts not exists. echo hosts
result=$(grep -i "$ip" -A 1 /etc/hosts)

if [[ "$result" == "" ]]; then
  echo "$ip $hostname" >> /etc/hosts
fi





/usr/bin/expect <<-EOF

set time 30
spawn ssh-copy-id $hostname
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$passwd\r" }
}
expect eof
EOF


